package pl.elka.pobr.ppr.logic.recognition;

import java.util.Vector;

import pl.elka.pobr.ppr.logic.Coord;
import pl.elka.pobr.ppr.logic.ObjectType;
import pl.elka.pobr.ppr.utils.Log;

public class Segment {

    private static final String LOG_TAG = "Segment";
    private Vector<Coord> mPixels; // pixels that belongs to this segment
    private int mSegId;
    private MomentsStorage mMoments;
    private int mS;
    private int mL;
    private int mGeomCX;
    private int mGeomCY;
    private int mWeightCX;
    private int mWeightCY;
    private int mMaxDiameter;
    private int mCircumscribedRectangleArea; // area of rectangle that contains the segment inside
    private ObjectType mType; // type of recognized object
    private double mProbability; // probability that this object is that type

    public Segment(int id) {
        mType = ObjectType.NOT_INTERESTING;
        mProbability = -1;
        mPixels = new Vector<Coord>();
        mSegId = id;
    }

    public void addItem(Coord e) {
        mPixels.add(e);
    }

    public Vector<Coord> getPixels() {
        return mPixels;
    }

    public int getSegId() {
        return mSegId;
    }

    public MomentsStorage getMoments() {
        return mMoments;
    }

    public void setValues(MomentsStorage mMoments, int pS, int pL, int pGeomCX, int pGeomCY, int pWeightCX, int pWeightCY) {
        this.mMoments = mMoments;
        mS = pS;
        mL = pL;
        mGeomCX = pGeomCX;
        mGeomCY = pGeomCY;
        mWeightCX = pWeightCX;
        mWeightCY = pWeightCY;
        int[] mm = MomentsComputer.findMinAndMax(mPixels);
        int diameterX = mm[1] - mm[0];
        int diameterY = mm[3] - mm[2];
        mCircumscribedRectangleArea = diameterX * diameterY;
        mMaxDiameter = Math.max(diameterX, diameterY);
    }

    public int getSegmentSize() {
        return mPixels.size();
    }

    public void printValues() {
        Log.d(LOG_TAG, "seg ID=" + mSegId);
        Log.d(LOG_TAG, "seg geomC=" + mGeomCX + "," + mGeomCY);
        Log.d(LOG_TAG, "seg weightC=" + mWeightCX + "," + mWeightCY);
        Log.d(LOG_TAG, "S=" + mS);
        Log.d(LOG_TAG, "L=" + mL);
        Log.d(LOG_TAG, "W3=" + mMoments.W3);
        Log.d(LOG_TAG, "W7_Lp1=" + mMoments.W7_Lp1);
        Log.d(LOG_TAG, "W8_Lp2=" + mMoments.W8_Lp2);
        for (int i = 1; i < 11; ++i) {
            Log.d(LOG_TAG, "M" + i + "=" + mMoments.M[i]);
        }
    }

    public ObjectType getType() {
        return mType;
    }

    public void setType(ObjectType mType) {
        this.mType = mType;
    }

    public double getProbability() {
        return mProbability;
    }

    public void setProbability(double mProbability) {
        this.mProbability = mProbability;
    }

    public int getGeomCX() {
        return mGeomCX;
    }

    public int getGeomCY() {
        return mGeomCY;
    }

    public int getWeightCX() {
        return mWeightCX;
    }

    public int getWeightCY() {
        return mWeightCY;
    }

    public int getMaxDiameter() {
        return mMaxDiameter;
    }

    public int getCircumscribedRectangleArea() {
        return mCircumscribedRectangleArea;
    }
}
